package com.wjs.spring.test;

import com.cyl.spring.SpringConfiguration;
import com.cyl.spring.service.StudentService;
import com.wjs.spring.bean.*;
import com.wjs.spring.service.TeacherService;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;


public class test01 {
    @Test
    public void test(){
        ApplicationContext applicationContext = new ClassPathXmlApplicationContext("Spring.xml");
        User userBean = applicationContext.getBean("userBean", User.class);
        System.out.println(userBean);
        Order order = applicationContext.getBean("order", Order.class);
        System.out.println(order);
        Student student = applicationContext.getBean("student", Student.class);
        System.out.println(student);
        Vip vip = applicationContext.getBean("vip", Vip.class);
        System.out.println(vip);
    }

    @Test
    public void test02() {
        ApplicationContext applicationContext = new ClassPathXmlApplicationContext("Spring2.xml");
    }

    @Test
    public void test03(){
        ApplicationContext applicationContext = new ClassPathXmlApplicationContext("Spring.xml");
        Animal animal = applicationContext.getBean("animal", Animal.class);
        System.out.println(animal);
    }

    @Test
    public void testAutowired(){
        ApplicationContext applicationContext = new ClassPathXmlApplicationContext("Spring3.xml");
        TeacherService service = applicationContext.getBean("teacherService", TeacherService.class);
        service.service();
    }

    @Test
    public void testResource(){
        ApplicationContext applicationContext = new ClassPathXmlApplicationContext("Spring-Resource.xml");
        StudentService studentService = applicationContext.getBean("studentService", StudentService.class);
        studentService.service();
    }

    @Test
    public void testNoXml(){
        ApplicationContext applicationContext = new AnnotationConfigApplicationContext(SpringConfiguration.class);
        StudentService studentService = applicationContext.getBean("studentService", StudentService.class);
        studentService.service();
    }
}
